﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Workflow;
using Moq;
using Xrm.Framework.Test.Unit.Moq;
using Microsoft.Xrm.Sdk.Query;
using Xrm.Solutions.FrameworkSample.Workflow;


namespace Xrm.Solutions.FrameworkSample.XrmUnitTests.WFActivities
{
    [TestClass]
    public class TestOpportunitiesTotalUsingMoq : WFActivityUnitTest
    {
        #region Instance Variables

        //TODO: Declare your variables for setup and verification

        #endregion

        #region Setup

        protected override Activity SetupActivity()
        {

            //TODO: Setup your Stubs & Shim

            base.OrganizationServiceMock.Setup(service => service.RetrieveMultiple(It.IsAny<QueryByAttribute>()))
                .Returns( () =>
                    {
                        Entity opp1 = new Entity("opportunity");
                        opp1.Attributes.Add("actualvalue", new Money(200));
                        Entity opp2= new Entity("opportunity");
                        opp2.Attributes.Add("actualvalue", new Money(300));
                        Entity opp3 = new Entity("opportunity");
                        EntityCollection opps = new EntityCollection();
                        opps.Entities.AddRange(opp1, opp2, opp3);
                        return opps;
                    }
                );

            base.Inputs.Add("AccountReference",
                new EntityReference("account", Guid.NewGuid()));

            //TODO: Create your Activity
            Activity activity = new TotalOpportunitiesLateBound();

            return activity;
        }

        #endregion

        #region Test

        [TestMethod]
        public void RunTestOpportunitiesTotalUsingMoq()
        {
            base.Test();
        }

        #endregion

        #region Verify

        protected override void Verify()
        {
            Assert.IsNull(Error);

            Money actualTotal = this.Outputs["Total"] as Money;
            decimal expectedTotal = 500;

            Assert.IsNotNull(actualTotal);
            Assert.AreEqual(expectedTotal, actualTotal.Value);
        }

        #endregion
    }
}
